<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

//
//
//
function doChannelSelect(selectedItems) {
  doPickerPopupAction('<c:url value="/mt/categorySearchPickerPopupMultiSelect.do"/>', 'setChannels', 301, null, selectedItems);
}

//
//
//
function setChannels(ids, names) {
  document.epUserTemplateShortcutsForm.contentTypeId.value = 6;
  setContent(ids, names);
}

//
//
//
function doProgramSelect(selectedItems) {
  doPickerPopupAction('<c:url value="/mt/pickerPopupSearchMultiSelect.do"/>', 'setPrograms', 301, null, selectedItems);
}

//
//
//
function setPrograms(ids, names) {
  document.epUserTemplateShortcutsForm.contentTypeId.value = 301;
  setContent(ids, names);
}

<c:forEach var="contentType" items="${epUserTemplateShortcutsView.map.contentTypes}">

function doContentSelect<c:out value="${contentType.value}"/>(selectedItems) {
  if (<c:out value="${contentType.value}"/> == 50) {
    doPickerPopupAction('<c:url value="/mt/pickerPopupSearchMultiSelect.do"/>',
      'setContent<c:out value="${contentType.value}"/>', <c:out value="${contentType.value}"/>, null, selectedItems, 'NAME');
  }
  else {
    doPickerPopupAction('<c:url value="/mt/pickerPopupSearchMultiSelect.do"/>',
      'setContent<c:out value="${contentType.value}"/>', <c:out value="${contentType.value}"/>, null, selectedItems);
  }
}

function setContent<c:out value="${contentType.value}"/>(ids, names) {
  document.epUserTemplateShortcutsForm.contentTypeId.value = <c:out value="${contentType.value}"/>;
  setContent(ids, names);
}

</c:forEach>

//
//
//
function setContent(ids, names) {
  document.epUserTemplateShortcutsForm.selectedIds.length = 0;
  for (var index = 0; index < ids.length; index++) {
    var option = new Option(names[index], ids[index], true, true);
    document.epUserTemplateShortcutsForm.selectedIds.options[index] = option;
  }
  document.epUserTemplateShortcutsForm.action = "<c:url value="/ep/userTemplateShortcutsAdd.do"/>";
  document.epUserTemplateShortcutsForm.submit();
}

//
//
//
function onChangeContentType() {
  var form = document.epUserTemplateShortcutsForm;
  var selectedIndex = form.contentType.selectedIndex;
  var contentType = form.contentType[selectedIndex].value;
  var label = "<bean-el:message key="button.content.select" bundle="ep.messages"/>"
  if (contentType == 6) {
    label = "<bean-el:message key="button.channels.select" bundle="ep.messages"/>"
  }
  else if (contentType == 301) {
    label = "<bean-el:message key="button.programs.select" bundle="ep.messages"/>"
  }
  form.btnSelect.value = label;
}

//
//
//
function doShortcutsAdd(form) {
  var selectedIndex = form.contentType.selectedIndex;
  var contentType = form.contentType[selectedIndex].value;
  var selectedItems = "";

  if (contentType == 6) {
<c:forEach var="shortcut" items="${epUserTemplateShortcutsView.map.shortcuts}" varStatus="status">
    if (<c:out value="${shortcut.map.contentType.value}"/> == 6) {
      if (selectedItems.length == 0) {
        selectedItems += '<c:out value="${shortcut.map.id}"/>';
      }
      else {
        selectedItems += ';' + '<c:out value="${shortcut.map.id}"/>';
      }
    }
</c:forEach>
    doChannelSelect(selectedItems);
  }
  else if (contentType == 301) {
<c:forEach var="shortcut" items="${epUserTemplateShortcutsView.map.shortcuts}" varStatus="status">
    if (<c:out value="${shortcut.map.contentType.value}"/> == 301) {
      if (selectedItems.length == 0) {
        selectedItems += '<c:out value="${shortcut.map.id}"/>';
      }
      else {
        selectedItems += ';' + '<c:out value="${shortcut.map.id}"/>';
      }
    }
</c:forEach>
    doProgramSelect(selectedItems);
<c:forEach var="contentType" items="${epUserTemplateShortcutsView.map.contentTypes}">
  } else if (contentType == <c:out value="${contentType.value}"/>) {
  <c:forEach var="shortcut" items="${epUserTemplateShortcutsView.map.shortcuts}" varStatus="status">
    if (<c:out value="${shortcut.map.contentType.value}"/> == <c:out value="${contentType.value}"/>) {
      if (selectedItems.length == 0) {
        selectedItems += '<c:out value="${shortcut.map.id}"/>';
      }
      else {
        selectedItems += ';' + '<c:out value="${shortcut.map.id}"/>';
      }
    }
  </c:forEach>
    doContentSelect<c:out value="${contentType.value}"/>(selectedItems);
</c:forEach>
  }
}

//
//
//
function doShortcutsRemove(form) {
  form.action = "<c:url value="/ep/userTemplateShortcutsRemove.do"/>";
  form.submit();
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>

<c:set var="removeImg">
<img src="<%= ctxPath %>/ep/images/action/icon_remove.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>">
</c:set>

<form name="epUserTemplateShortcutsForm" method="post">
<input type="hidden" name="userTemplateId" value="<c:out value='${epUserTemplateShortcutsView.map.id}'/>"/>
<input type="hidden" name="contentTypeId"/>
<input type="hidden" name="selectedId"/>

<select name="selectedIds" multiple="multiple" size="0"></select>
<script language="JavaScript1.2">
var theform = document.forms['epUserTemplateShortcutsForm'];
theform.selectedIds.style.visibility = 'hidden';
theform.selectedIds.style.display = 'none';
</script>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
   <td valign="top" width="100%">
      <div class="pageTitle">
      <bean-el:message key="ep.user.template.view.page.title" bundle="ep.messages" arg0="${epUserTemplateShortcutsView.map.name}"/>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.user.template.shortcuts.page.subtitle" bundle="ep.messages"/></span>
        <span class="right">
          <nobr>
            <bean-el:message key="ep.header.name.type" bundle="ep.messages"/>:
            <select name="contentType" onchange="onChangeContentType()">
            <option value="6" selected="selected"><bean-el:message key="ep.channels" bundle="ep.messages"/></option>
            <option value="301"><bean-el:message key="ep.programs" bundle="ep.messages"/></option>
<c:forEach var="contentType" items="${epUserTemplateShortcutsView.map.contentTypes}">
            <option value="<c:out value="${contentType.value}"/>"><c:out value="${contentType.label}"/></option>
</c:forEach>
            </select>
            <input type="button" name="btnSelect" class="titleButton" value='<bean-el:message key="button.channels.select" bundle="ep.messages"/>' onclick="doShortcutsAdd(this.form);">
          </nobr>
        </span>
      </div>

<c:if test="${not empty epUserTemplateShortcutsView.map.shortcuts}">
      <div class="globalButtonWrap">
         <input type="button" name="actionSelectAll" class="globalButton"
          onClick="check(this.form.shortcutIds, this);"
          value="<bean-el:message key="button.selectAll" bundle="ep.messages"/>">
        <input type="button" name="actionRemove" class="globalButton"
          onClick="if (isAnyChecked(this.form.shortcutIds, '<bean-el:message key="ep.shortcuts.atLeastOne" bundle="ep.messages"/>', '')) doShortcutsRemove(this.form);"
          value="<bean-el:message key="button.remove" bundle="ep.messages"/>">
      </div>
</c:if>
      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
          <th id="Checkboxes" width="1%">&nbsp;</th>
          <th id="Name" align="left"><bean-el:message key="ep.header.name.shortcut" bundle="ep.messages"/></th>
          <th id="Type" align="left" width="5%"><bean-el:message key="ep.header.name.type" bundle="ep.messages"/></th>
          <th id="Description" align="left"><bean-el:message key="ep.header.description" bundle="ep.messages"/></th>
          <th id="Actions" align="left" width="7%"><bean-el:message key="ep.header.actions" bundle="ep.messages"/></th>
        </tr>

<c:forEach var="shortcut" items="${epUserTemplateShortcutsView.map.shortcuts}" varStatus="status">
      <c:url var="removeUrl" value="/ep/userTemplateShortcutsRemove.do">
        <c:param name="userTemplateId" value="${epUserTemplateShortcutsView.map.id}"/>
        <c:param name="shortcutId" value="${shortcut.map.contentType.value}:${shortcut.map.id}"/>
      </c:url>

      <c:choose>
        <c:when test="${(status.count + 1) % 2 == 0}">
        <tr class="listEven">
        </c:when>
        <c:otherwise>
        <tr class="listOdd">
        </c:otherwise>
      </c:choose>
          <td headers="Checkboxes" align="center">
            <input type="checkbox" name="shortcutIds"
              onClick="update(this.form.shortcutIds, this.form.actionSelectAll);"
              value="<c:out value="${shortcut.map.contentType.value}"/>:<c:out value="${shortcut.map.id}"/>"/>
          </td>

          <td headers="Name"><c:out value="${shortcut.map.name}"/></td>
          <td headers="Type"><c:out value="${shortcut.map.contentType.label}"/></td>
          <td headers="Description"><c:out value="${shortcut.map.description}"/></td>
          <td headers="Actions"><a href="<c:out value="${removeUrl}"/>"><c:out value='${removeImg}' escapeXml="false"/></a></td>
        </tr>
</c:forEach>

<c:if test="${empty epUserTemplateShortcutsView.map.shortcuts}">
        <tr class="listOdd">
          <td align="center" colspan="5">
            <bean-el:message key="ep.user.templates.shortcuts.noFound" bundle="ep.messages"/>
          </td>
        </tr>
</c:if>
      </table>
<c:if test="${not empty epUserTemplateShortcutsView.map.shortcuts}">
      <%@ include file="/mc/common/pager.jsp" %>
</c:if>
    </td>
  </tr>
</table>
</form>
